import {
	refreshToken
} from '@/api/currency.js'

let promise;
export function refreshTokenFun() {

	if (promise) {
		return promise
	}

	// new
	promise = new Promise(async (resolve, reject) => {
		const resp = await refreshToken({
			refresh_token: uni.getStorageSync('refresh_token').token
		})

		// 储存token
		uni.setStorageSync('jwt_token', resp.data.jwt);
		uni.setStorageSync('refresh_token', resp.data.refresh_token);

		// 请求成功
		resolve(resp?.code == 200);
	})

	promise.finally(() => {
		promise = null;
	})

	return promise;
}